package blog.controller;

import blog.entity.Menu;
import blog.service.MenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller @RequestMapping("/menu")
public class MenuController {
    @Resource
    private MenuService menuService;
    @RequestMapping("")
    public String gotoMenuList(Map map){
        List<Menu> menuList = menuService.getMenuList();
        map.put("menuList",menuList);
        return "menu/menu-list";
    }
    @RequestMapping("/delete/{id}")
    public String deleteMenu(@PathVariable("id") Integer id){
        menuService.deleteMenuById(id);
        return "forward:/menu";
    }
    @RequestMapping("/edit/{id}")
    public String editMenu(@PathVariable("id") Integer id,Map map){
        Menu menu = menuService.getMenuById(id);
        map.put("menu",menu);
        return "menu/menu-edit";
    }
    @RequestMapping("/updateMenu")
    public String editMenu(Menu menu){
        menuService.updateMenu(menu);
        return "forward:/menu";
    }
    @RequestMapping("/insertMenu")
    public String insertMenu(Menu menu){
        menuService.addMenu(menu);
        return "forward:/menu";
    }
}
